# AfD-specific findings
stayer_ames <- rio::import("est/stayer_analyses_marginal_effects_main.csv")
stayer_desc <- rio::import("est/stayer_analyses_descriptives_main.csv")
stayer_info <-
  rio::import("est/stayer_analyses_model_info_main.csv") %>%
  dplyr::mutate(spec = dplyr::case_when(
    is.na(spec) ~ "All",
    spec == "ltr_since_3 == 0" ~ "Moved last 3", 
    spec == "ltr_since_5 == 0" ~ "Moved last 5", 
    spec == "ltr_since_3 == 1" ~ "Since 3", 
    spec == "ltr_since_5 == 1" ~ "Since 5"
  ))


## Long-term resident analyses

### Within-effects

#### AfD Support (Party ID) by Homeownership and Income

##### Five years, regular controls 
ggvote_plot_mfx2(
  ames_data = stayer_ames,
  desc_data = stayer_desc,
  model_ids = c(209, 224),
  add_descriptives = TRUE,
  d = "cmr_arm_cwu",
  x1  = "Homeownership",
  x2 = "log_hinc_eq",
  x2_continuous = TRUE,
  ytitle = "Marginal Effect",
  xtitle = "Log. Equivalized Household Income",
  font_size = 15L
) %>%
  ggsave(
    plot = .,
    filename = paste0("afd-sup-own-inc-5", "-1.pdf"),
    path = "fig",
    width = 8,
    height = 4,
    dpi = 300,
    limitsize = FALSE
  )

##### Five years, controls plus
ggvote_plot_mfx2(
  ames_data = stayer_ames,
  desc_data = stayer_desc,
  model_ids = c(210, 225),
  add_descriptives = TRUE,
  d = "cmr_arm_cwu",
  x1  = "Homeownership",
  x2 = "log_hinc_eq",
  x2_continuous = TRUE,
  ytitle = "Marginal Effect",
  xtitle = "Log. Equivalized Household Income",
  font_size = 15L
) %>%
  ggsave(
    plot = .,
    filename = paste0("afd-sup-own-inc-5-plus", "-1.pdf"),
    path = "fig",
    width = 8,
    height = 4,
    dpi = 300,
    limitsize = FALSE
  )


##### Less than five years, regular controls 
ggvote_plot_mfx2(
  ames_data = stayer_ames,
  desc_data = stayer_desc,
  model_ids = c(197, 218),
  add_descriptives = TRUE,
  d = "cmr_arm_cwu",
  x1  = "Homeownership",
  x2 = "log_hinc_eq",
  x2_continuous = TRUE,
  ytitle = "Marginal Effect",
  xtitle = "Log. Equivalized Household Income",
  font_size = 15L
) %>%
  ggsave(
    plot = .,
    filename = paste0("afd-sup-own-inc-less5", "-1.pdf"),
    path = "fig",
    width = 8,
    height = 4,
    dpi = 300,
    limitsize = FALSE
  )

##### Less than three years, regular controls 
ggvote_plot_mfx2(
  ames_data = stayer_ames,
  desc_data = stayer_desc,
  model_ids = c(191, 215),
  add_descriptives = TRUE,
  d = "cmr_arm_cwu",
  x1  = "Homeownership",
  x2 = "log_hinc_eq",
  x2_continuous = TRUE,
  ytitle = "Marginal Effect",
  xtitle = "Log. Equivalized Household Income",
  font_size = 15L
) %>%
  ggsave(
    plot = .,
    filename = paste0("afd-sup-own-inc-less3", "-1.pdf"),
    path = "fig",
    width = 8,
    height = 4,
    dpi = 300,
    limitsize = FALSE
  )

##### Five years, discrete moderator
ggvote_plot_mfx2(
  ames_data = stayer_ames,
  desc_data = stayer_desc,
  model_ids = c(389, 404),
  add_descriptives = TRUE,
  d = "cmr_arm_cwu",
  x1  = "Homeownership",
  x2 = "log_hinc_eq_cat",
  x2_continuous = FALSE,
  ytitle = "Marginal Effect",
  xtitle = "Log. Equivalized Household Income",
  font_size = 15L
) %>%
  ggsave(
    plot = .,
    filename = paste0("afd-sup-own-inc-5-discrete", "-1.pdf"),
    path = "fig",
    width = 8,
    height = 4,
    dpi = 300,
    limitsize = FALSE
  )

##### Three years, regular controls 
ggvote_plot_mfx2(
  ames_data = stayer_ames,
  desc_data = stayer_desc,
  model_ids = c(203, 221),
  add_descriptives = TRUE,
  d = "cmr_arm_cwu",
  x1  = "Homeownership",
  x2 = "log_hinc_eq",
  x2_continuous = TRUE,
  ytitle = "Marginal Effect",
  xtitle = "Log. Equivalized Household Income",
  font_size = 15L
) %>%
  ggsave(
    plot = .,
    filename = paste0("afd-sup-own-inc-3", "-1.pdf"),
    path = "fig",
    width = 8,
    height = 4,
    dpi = 300,
    limitsize = FALSE
  )

##### One year, regular controls 
ggvote_plot_mfx2(
  ames_data = stayer_ames,
  desc_data = stayer_desc,
  model_ids = c(185, 212),
  add_descriptives = TRUE,
  d = "cmr_arm_cwu",
  x1  = "Homeownership",
  x2 = "log_hinc_eq",
  x2_continuous = TRUE,
  ytitle = "Marginal Effect",
  xtitle = "Log. Equivalized Household Income",
  font_size = 15L
) %>%
  ggsave(
    plot = .,
    filename = paste0("afd-sup-own-inc-1", "-1.pdf"),
    path = "fig",
    width = 8,
    height = 4,
    dpi = 300,
    limitsize = FALSE
  )

#### AfD Support (Party ID) by Homeownership, Income, and Locality
ggvote_plot_mfx2(
  ames_data = stayer_ames,
  desc_data = stayer_desc,
  model_ids = c(254),
  add_descriptives = TRUE,
  d = "cmr_arm_cwu",
  x2 = "log_hinc_eq",
  x1 = "gtyp3",
  x2_continuous = TRUE,
  ytitle = "Marginal Effect",
  xtitle = "Log. Equivalized Household Income",
  font_size = 15L
) %>%
  ggsave(
    plot = .,
    filename = paste0("afd-sup-own-inc-loc-renter-5", "-1.pdf"),
    path = "fig",
    width = 10,
    height = 4,
    dpi = 300,
    limitsize = FALSE
  )

### Extra covariates
ggvote_plot_mfx2(
  ames_data = stayer_ames,
  desc_data = stayer_desc,
  model_ids = c(255),
  add_descriptives = TRUE,
  d = "cmr_arm_cwu",
  x2 = "log_hinc_eq",
  x1 = "gtyp3",
  x2_continuous = TRUE,
  ytitle = "Marginal Effect",
  xtitle = "Log. Equivalized Household Income",
  font_size = 15L
) %>%
  ggsave(
    plot = .,
    filename = paste0("afd-sup-own-inc-loc-renter-5-plus", "-1.pdf"),
    path = "fig",
    width = 10,
    height = 4,
    dpi = 300,
    limitsize = FALSE
  )

#### Five years, discrete moderator
ggvote_plot_mfx2(
  ames_data = stayer_ames,
  desc_data = stayer_desc,
  model_ids = c(434),
  add_descriptives = TRUE,
  d = "cmr_arm_cwu",
  x2 = "log_hinc_eq_cat",
  x1 = "gtyp3",
  x2_continuous = FALSE,
  ytitle = "Marginal Effect",
  xtitle = "Log. Equivalized Household Income",
  font_size = 15L
) %>%
  ggsave(
    plot = .,
    filename = paste0("afd-sup-own-inc-loc-renter-5-discrete", "-1.pdf"),
    path = "fig",
    width = 10,
    height = 4,
    dpi = 300,
    limitsize = FALSE
  )

### Alternative moderator: Rent levels
ggvote_plot_mfx2(
  ames_data = stayer_ames,
  desc_data = stayer_desc,
  model_ids = c(299),
  add_descriptives = TRUE,
  d = "cmr_arm_cwu",
  x2 = "log_hinc_eq",
  x1 = "cmr_arm_cat",
  x2_continuous = TRUE,
  ytitle = "Marginal Effect",
  xtitle = "Log. Equivalized Household Income",
  font_size = 15L
) %>%
  ggsave(
    plot = .,
    filename = paste0("afd-sup-own-inc-loc-rentlevels-renter", "-1.pdf"),
    path = "fig",
    width = 10,
    height = 4,
    dpi = 300,
    limitsize = FALSE
  )

### Alternative moderator: Rent changes
ggvote_plot_mfx2(
  ames_data = stayer_ames,
  desc_data = stayer_desc,
  model_ids = c(344),
  add_descriptives = TRUE,
  d = "cmr_arm_cwu",
  x2 = "log_hinc_eq",
  x1 = "cmr_arm_chg_cat",
  x2_continuous = TRUE,
  ytitle = "Marginal Effect",
  xtitle = "Log. Equivalized Household Income",
  font_size = 15L
) %>%
  ggsave(
    plot = .,
    filename = paste0("afd-sup-own-inc-loc-rentchanges-renter", "-1.pdf"),
    path = "fig",
    width = 10,
    height = 4,
    dpi = 300,
    limitsize = FALSE
  )

### Vote choice
#### AfD Vote Choice by Homeownership and Income
ggvote_plot_mfx2(
  ames_data = stayer_ames,
  desc_data = stayer_desc,
  model_ids = c(749, 764),
  add_descriptives = TRUE,
  d = "cmr_arm_cwu",
  x1  = "Homeownership",
  x2 = "log_hinc_eq",
  x2_continuous = TRUE,
  ytitle = "Marginal Effect",
  xtitle = "Log. Equivalized Household Income",
  font_size = 15L
) %>%
  ggsave(
    plot = .,
    filename = paste0("afd-vote-own-inc", "-1.pdf"),
    path = "fig",
    width = 8,
    height = 4,
    dpi = 300,
    limitsize = FALSE
  )

#### AfD Vote Choice by Homeownership, Income, and Locality
ggvote_plot_mfx3(
  ames_data = stayer_ames,
  desc_data = stayer_desc,
  model_ids = c(794, 809),
  add_descriptives = TRUE,
  d = "cmr_arm_cwu",
  x1  = "Homeownership",
  x2 = "log_hinc_eq",
  x3 = "gtyp3",
  x2_continuous = TRUE,
  subset_x1 = "Renters",
  ytitle_left = "Marginal Effect",
  ytitle_right = "",
  xtitle = "Log. Equivalized Household Income",
  font_size = 15L
) %>%
  ggsave(
    plot = .,
    filename = paste0("afd-vote-own-inc-loc", "-1.pdf"),
    path = "fig",
    width = 10,
    height = 4,
    dpi = 300,
    limitsize = FALSE
  )
